/**
 * 
 */
package de.uni_leipzig.informatik.asv.unsupervised_pos_tagger.data;
import java.util.ArrayList;
import it.unimi.dsi.fastutil.doubles.DoubleArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
/**
 * 
 * @author Christoph Teichmann
 * created May 29, 2014 7:17:51 PM
 * @version 0.1
 */
public class Word
{
	/**
	 * 
	 */
	private final double amount;
	/**
	 * 
	 * @return the identity
	 */
	public int getIdentity()
	{return identity;}
	/**
	 * @return the language
	 */
	public int getLanguage()
	{return language;}
	/**
	 * 
	 * @param identity
	 * @param language
	 */
	public Word(int identity, int language, double amount)
	{
		this.identity = identity;
		this.language = language;
		this.amount = amount;
	}
	/**
	 * @return the amount
	 */
	public double getAmount()
	{return amount;}
	/**
	 * 
	 */
	private final DoubleArrayList connWeights = new DoubleArrayList();
	/**
	 * 
	 */
	private final ArrayList<Word> connWords = new ArrayList<>();
	/**
	 * 
	 */
	private final IntArrayList connLabels = new IntArrayList();
	/**
	 * 
	 *
	 * @return
	 */
	public int getNumberOfConnections()
	{return this.connLabels.size();}
	/**
	 *
	 * @param word
	 * @param language
	 * @param label
	 * @param weight
	 */
	public void addConnection(Word w, int label, double weight)
	{
		this.connWeights.add(weight);
		this.connLabels.add(label);
		this.connWords.add(w);
		w.addReverseConnection(this, label, weight);
	}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public int getConnectionLabel(int number)
	{return this.connLabels.getInt(number);}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public double getConnectionWeight(int number)
	{return this.connWeights.getDouble(number);}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public Word getConnectedWord(int number)
	{return this.connWords.get(number);}
	/**
	 * 
	 */
	private final int identity;
	/**
	 * 
	 */
	private final int language;
	/**
	 * 
	 */
	private final DoubleArrayList featWeights = new DoubleArrayList();
	/**
	 * 
	 */
	private final IntArrayList featNames = new IntArrayList();
	/**
	 * 
	 *
	 * @param name
	 * @param value
	 */
	public void addFeature(int name, double value)
	{
		this.featWeights.add(value);
		this.featNames.add(name);
	}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public double getFeatureValue(int number)
	{return this.featWeights.getDouble(number);}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public int getFeatureName(int number)
	{return featNames.getInt(number);}
	/**
	 * 
	 *
	 * @return
	 */
	public int getNumberOfFeatures()
	{return this.featNames.size();}
	/**
	 *
	 * @param w
	 * @param label
	 * @param val
	 */
	private void addReverseConnection(Word w, int label, double val)
	{
		this.reverseConnLabels.add(label);
		this.reverseConnWeights.add(val);
		this.reverseConnWords.add(w);
	}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public int getReverseConnectionLabel(int number)
	{return this.reverseConnLabels.getInt(number);}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public double getReverseConnectionWeight(int number)
	{return this.reverseConnWeights.getDouble(number);}
	/**
	 * 
	 *
	 * @param number
	 * @return
	 */
	public Word getReverseConnectedWord(int number)
	{return this.reverseConnWords.get(number);}
	/**
	 * 
	 *
	 * @return
	 */
	public int getNumberOfReverseConnections()
	{return this.reverseConnLabels.size();}
	/**
	 * 
	 */
	private final DoubleArrayList reverseConnWeights = new DoubleArrayList();
	/**
	 * 
	 */
	private final ArrayList<Word> reverseConnWords = new ArrayList<>();
	/**
	 * 
	 */
	private final IntArrayList reverseConnLabels = new IntArrayList();
}